package com.example.park2212.repair

import androidx.lifecycle.MutableLiveData
import com.example.lib_base.entity.RepairBean
import com.example.lib_base.entity.RepairBeanItem
import com.example.lib_base.entity.SearchBean
import com.example.lib_base.mvvm.BaseViewModel
import com.example.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class RepairViewModel @Inject constructor(val apiService: ApiService):BaseViewModel() {

    var getRepairSuccess = MutableLiveData<RepairBean>()

    fun getRepair(){
        httpRequest({
            apiService.repair()
        },getRepairSuccess::postValue)
    }
    fun getRepairByUname(repairName:String){
        httpRequest({
            apiService.getRepairByUname(repairName)
        },{getRepairSuccess.value = it})
    }

    var getPairByNoSuccess = MutableLiveData<RepairBeanItem>()
    fun getPairByNo(orderNumber:String){
        httpRequest({
            apiService.getPairByNo(orderNumber)
        },getPairByNoSuccess::postValue)
    }

    var getPairByIdSuccess = MutableLiveData<RepairBeanItem>()
    fun getPairById(id:Int){
        httpRequest({
            apiService.getPairById(id)
        },getPairByIdSuccess::postValue)
    }


    var updatePairSuccess = MutableLiveData<RepairBeanItem>()
    fun updatePair(id:Int,beanItem: RepairBeanItem){
        httpRequest({
            apiService.updateRepair(id,mapToBody(beanItem))
        },updatePairSuccess::postValue)
    }

    var addRepairSuccess = MutableLiveData<RepairBeanItem>()
    fun addRepair(beanItem: RepairBeanItem){
        httpRequest({
            apiService.addRepair(mapToBody(beanItem))
        },addRepairSuccess::postValue)
    }

    val deleteRepairSuccess = MutableLiveData<String>()
    fun deleteRepair(id:Int){
        httpRequest({
            apiService.deleteRepair(id)
        },deleteRepairSuccess::postValue)
    }

    var insertSearch = MutableLiveData<Long>()


}